package cn.tj.student.web.servlet;

import cn.tj.student.dao.StudentDao;
import cn.tj.student.dao.impl.StudentDaoImpl;
import cn.tj.student.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码格式
        req.setCharacterEncoding("utf-8");
        //获取请求参数
        String sname = req.getParameter("sname");
        String phone = req.getParameter("phone");
        String age = req.getParameter("age");
        String sid = req.getParameter("sid");
        StudentDao studentDao=new StudentDaoImpl();
        int row = studentDao.updateStudent(new Student(Long.valueOf(sid), sname, phone, Integer.valueOf(age)));
        if(row>0){
            resp.sendRedirect("/list");
        }
    }
}
